#ifndef BONJOURSERVICEREGISTER_H
#define BONJOURSERVICEREGISTER_H

#include <QtCore/QObject>
#include <QSocketNotifier>

#ifdef _WIN32
	typedef unsigned short UINT16;
	typedef unsigned int UINT18;
	typedef unsigned char UINT8;
	typedef signed char INT8;
	typedef short INT16;
#endif

#include <dns_sd.h>

#include "../Common/bonjourrecord.h"


/** Class allows for Bonjour services to be registered. */
class BonjourServiceRegister : public QObject
{
	Q_OBJECT

	public:
		BonjourServiceRegister(QObject *parent) : QObject(parent),
			dnssref(0), bonjourSocket(0) {}

		~BonjourServiceRegister();

		void registerService(const BonjourRecord &record, quint16 servicePort);
		BonjourRecord registeredRecord() const { return finalRecord; }

	signals:
		void error(DNSServiceErrorType error);
		void serviceRegistered(const BonjourRecord &record);

	private slots:
		void bonjourSocketReadyRead();

	private:
		static void DNSSD_API bonjourRegisterService(DNSServiceRef sdRef,
							     DNSServiceFlags,
							     DNSServiceErrorType errorCode,
							     const char *name,
							     const char *regtype,
							     const char *domain,
							     void *context);

		DNSServiceRef dnssref;
		QSocketNotifier *bonjourSocket;
		BonjourRecord finalRecord;
};

#endif // BONJOURSERVICEREGISTER_H
